home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / CullGroupSample / Source / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  4.1 KB  |  212 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        EVENTS            */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Windows.h>
  11. #include <ToolUtils.h>
  12.  
  13. #include <QD3D.h>
  14.  
  15. #include "myglobals.h"
  16. #include "myevents.h"
  17. #include "mymenus.h"
  18. #include "main.h"
  19. #include "misc.h"
  20. #include "qd3d_support.h"
  21. #include "process.h"
  22.  
  23. extern    WindowPtr    gModelWindow;
  24. extern    QD3DSetupOutputType        gModelViewInfo;
  25.  
  26. /****************************/
  27. /*    PROTOTYPES            */
  28. /****************************/
  29.  
  30. static void DoHighLevelEvent(void);
  31. static Boolean IsDAWindow(WindowPtr whichWindow);
  32. static OSErr  hasGotRequiredParams(AppleEvent *appEvent);
  33.  
  34.  
  35. /****************************/
  36. /*    CONSTANTS             */
  37. /****************************/
  38.  
  39. #define MIN_SLEEP            0L
  40. #define    NIL_MOUSE_REGION    0L
  41.  
  42.  
  43. /**********************/
  44. /*     VARIABLES      */
  45. /**********************/
  46.  
  47. EventRecord    gTheEvent;
  48.  
  49. /******************/
  50. /* HANDLE EVENTS  */
  51. /******************/
  52.  
  53. void HandleEvents()
  54. {
  55. char    theChar;
  56. GrafPtr    oldPort;
  57.         
  58.     WaitNextEvent(everyEvent,&gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION);
  59.                 
  60.     switch (gTheEvent.what)
  61.     {
  62.         case    nullEvent:
  63.                 HandleNullEvent();
  64.                 break;
  65.         case    mouseDown:
  66.                 HandleMouseDown();
  67.                 break;
  68.         case    keyDown:
  69.         case    autoKey:
  70.                 theChar    = gTheEvent.message & charCodeMask;
  71.                 if    ((gTheEvent.modifiers & cmdKey) != 0)
  72.                     HandleMenuChoice(MenuKey(theChar));
  73.                 else
  74.                     HandleKeyDown(theChar);
  75.                 break;
  76.         case    updateEvt:
  77.                 if (!IsDAWindow((WindowPtr)gTheEvent.message))
  78.                 {
  79.                     GetPort (&oldPort);
  80.                     SetPort ((WindowPtr)gTheEvent.message);
  81.                     BeginUpdate((WindowPtr)gTheEvent.message);
  82.                     DrawControls((WindowPtr)gTheEvent.message);
  83.                     
  84.                     if ((WindowPtr)gTheEvent.message == gModelWindow)
  85.                         UpdateModelWindow();
  86.                                             
  87.                     EndUpdate((WindowPtr)gTheEvent.message);
  88.                     SetPort(oldPort); 
  89.                 }
  90.                 else 
  91.                 {
  92.                     BeginUpdate((WindowPtr)gTheEvent.message);
  93.                     EndUpdate((WindowPtr)gTheEvent.message);
  94.                 }
  95.                 break;
  96.         case    kHighLevelEvent:
  97.                 DoHighLevelEvent();
  98.                 break;
  99.     }
  100. }
  101.  
  102.  
  103. /**************** DO HIGH LEVEL EVENT *****************/
  104.  
  105. static void DoHighLevelEvent(void)
  106. {
  107. OSErr    myErr;
  108.  
  109.     myErr = AEProcessAppleEvent(&gTheEvent);
  110. }
  111.  
  112.  
  113. /**********************/
  114. /* HANDLE MOUSE DOWN  */
  115. /**********************/
  116.  
  117. void HandleMouseDown(void)
  118. {
  119.     WindowPtr        whichWindow;
  120.     short             thePart;
  121.     long            menuChoice, windSize;
  122.     
  123.     thePart    =    FindWindow(gTheEvent.where, &whichWindow);
  124.     switch(thePart)
  125.     {
  126.         case    inMenuBar:
  127.                 menuChoice = MenuSelect(gTheEvent.where);
  128.                 HandleMenuChoice(menuChoice);
  129.                 break;
  130.         case    inSysWindow:
  131.                 SystemClick(&gTheEvent, whichWindow);
  132.                 break;
  133.         case    inDrag:
  134.                 DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds);
  135.                 break;
  136.         case    inGoAway:
  137.                     DisposeWindow (whichWindow);
  138.                 break;
  139.                 
  140.         case    inContent:
  141.                 SelectWindow(whichWindow);
  142.  
  143.                 break;
  144.                 
  145.         case    inGrow:
  146.                 windSize = GrowWindow(whichWindow, gTheEvent.where,
  147.                                     &(**GetGrayRgn()).rgnBBox);
  148.                 if (windSize != 0)
  149.                 {
  150.                     SetPort(whichWindow);
  151.                     EraseRect(&whichWindow->portRect);
  152.                     SizeWindow(whichWindow,LoWord(windSize),
  153.                                 HiWord(windSize), NORMAL_UPDATES);
  154.                     InvalRect(&whichWindow->portRect);
  155.                     
  156.                     if (whichWindow == gModelWindow)            // see if change Skeleton window
  157.                     {
  158.                         QD3D_ChangeDrawSize(&gModelViewInfo);
  159.                     }
  160.                 } 
  161.                 break;
  162.     }
  163. }
  164.  
  165. /*****************/
  166. /* Is DA Window? */
  167. /*****************/
  168. // DA WINDOWS HAVE NEGATEIVE windowKinds //
  169.  
  170. static Boolean IsDAWindow(WindowPtr whichWindow)
  171. {
  172.         if    (whichWindow == NIL_POINTER)
  173.                 return (false);
  174.         else
  175.                 return (((WindowPeek)whichWindow)->windowKind < 0);
  176. }
  177.  
  178.  
  179. /**********************/
  180. /* HANDLE NULL EVENT  */
  181. /**********************/
  182.  
  183. void HandleNullEvent()
  184. {
  185. //    DoModelWindowNullEvent();
  186.  
  187. }
  188.  
  189.  
  190. /******************** HANDLE KEY DOWN *******************/
  191.  
  192. void    HandleKeyDown(char theKey)
  193. {
  194.     #pragma unused(theKey)
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /*********************** MY APPLE EVENT: QUIT APPLICATION *************************/
  203.  
  204. pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply,
  205.                             SInt32 handlerRefcon)
  206. {
  207.     #pragma unused(theAppleEvent, reply, handlerRefcon)
  208.  
  209.     CleanQuit();
  210.     return(noErr);
  211. }
  212.